﻿namespace SVTTranslateTextEngine.Core
{
    /// <summary>
    /// This class handles the translate engine information accessing .
    /// </summary>
    public class ApiSetting
    {
        /// <summary>
        /// The amount of how many GoogleTranslateEngine object has been created.
        /// </summary>
        private static int m_TotalObjectAmount;

        /// <summary>
        /// The Application IDs of our Google Accounts
        /// </summary>
        private static readonly string[] m_AppIds = new[]
                                                        {
                                                            "AIzaSyB3SVFyzNrLeoUvp-6WXwOIV1iGEj_SwE0",
                                                            "AIzaSyBiJsKdJzN4r8sYRfvY4A4ErmcCR7gBAdc"
                                                        };

        /// <summary>
        /// Get the google translate engine applicatoin ID for Multiple IDs.
        /// Instantiate multiple objects , multiple accounts sharing application
        /// </summary>
        /// <returns></returns>
        public static string GetGoogleTranslateAppId()
        {
            string reVal = "";
            m_TotalObjectAmount++;
            if (m_TotalObjectAmount == int.MaxValue)
                m_TotalObjectAmount = 0;
            if (m_AppIds.Length > 1)
            {
                int index = m_TotalObjectAmount%m_AppIds.Length;
                reVal = m_AppIds[index];
            }
            else if (m_AppIds.Length == 1)
                reVal = m_AppIds[0];
            return reVal;
        }

        /// <summary>
        /// Get the google application ID from m_AppIds pool by the index.
        /// </summary>
        /// <param name="iAppIdIndex"></param>
        /// <returns></returns>
        public static string GetGoogleTranslateAppId(int iAppIdIndex)
        {
            return m_AppIds.Length > iAppIdIndex ? m_AppIds[iAppIdIndex] : m_AppIds[0];
        }

    }
}